package com.qf.service.impl;

import com.qf.dto.DeveloperDto;
import com.qf.mapper.DeveloperMapper;
import com.qf.mapper.ProjectMapper;
import com.qf.mapper.StageMapper;
import com.qf.model.Developer;
import com.qf.model.Project;
import com.qf.model.Stage;
import com.qf.page.PageResult;
import com.qf.page.QueryPageBean;
import com.qf.service.DeveloperService;
import com.qf.service.StageService;
import com.qf.utils.UUIDUtils;
import com.qf.vo.DeveloperVo;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class StageServiceImpl implements StageService {
    @Autowired
    private StageMapper stageMapper;
    @Autowired
    private ProjectMapper projectMapper;
    //分页查询+模糊查询
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer CurrentPage = queryPageBean.getCurrentPage();
        Integer PageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageResult pageResult = new PageResult();
        //当前页结果
        List<Stage> rows = stageMapper.findPage((CurrentPage-1)*PageSize, PageSize,queryString);
        //总记录数
        Long count = stageMapper.count(queryString);
        pageResult.setTotal(count);
        pageResult.setRows(rows);
        return pageResult;
    }

    //新建开发商并绑定工程
    @Override
    @Transactional
    public boolean add(Stage stage) {
        stage.setUpdatetime(new Date());
        stage.setSid(UUIDUtils.uuid());
        //新增stage
        int i = stageMapper.addOne(stage);
        if (i>0){
            return true;
        }
        return false;
    }


    //根据sid查询stage回显
    @Override
    public Stage findById(String sid) {
        Stage stage = stageMapper.findById(sid);

        return stage;
    }

    //修改developer
    @Override
    @Transactional
    public int edit(Stage stage) {
        stage.setUpdatetime(new Date());
        //修改developer
        int i = stageMapper.editOne(stage);
        return i;
    }

    //删除stage
    @Override
    @Transactional
    public int delete(String did) {
        int i = stageMapper.delete(did);
        return i;
    }
}
